package com.jwb.task;

import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.text.SimpleDateFormat;
import java.util.Date;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import com.alibaba.fastjson.JSONObject;
import com.jwb.pub.service.AttachFileDetailService;
import com.jwb.pub.service.UserDictService;
import com.jwb.util.ProtocolUtil;
import com.jwb.util.ToolsUtil;
import com.jwb.util.WxChatImgRevert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ResourceUtils;
import org.springframework.util.SocketUtils;

/**
 * @author: liuyn
 * @description :
 * @Date : 10:16 2019/04/17
 */
@Component
@Slf4j
@Async
public class TaskPub implements InitializingBean {

	@Autowired
	private UserDictService userDictService;

	@Scheduled(cron = "0 0/5 * * * ?")
	public void userDictData() {
		log.info("========系统字典更新开始========");
		try {
			JSONObject result = new JSONObject();
			// 项目的根目录路径
			String localpath =  System.getProperty("user.dir");
			String remotePath = URLDecoder.decode(ClassUtils.getDefaultClassLoader().getResource("").getPath(),"utf-8");
			String jspath = remotePath.substring(1) + "META-INF/resources/plugin/vue/js/dict.js";
			String localjs = localpath + "/src/main/resources/META-INF/resources/plugin/vue/js/dict.js";
			System.out.println(jspath);
			System.out.println(localjs);
			result = userDictService.generateUserDictJS(jspath,localjs);
			System.out.println(result.toString());

		} catch (Exception e) {
			e.printStackTrace();
		}
		log.info("========系统字典更新结束========");
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		userDictData();
	}

}